<template>
  <div style="padding: 8px;">
    <el-card v-loading="loading">
      <span>{{ $t("当前App版本为") }}:</span>
      <el-input v-model="versionCode" :disabled="ischeck" style="width: 200px"></el-input>
      <el-button v-if="isedit" style="margin-left: 20px" type="success" @click="edit">{{ $t("修改") }}
      </el-button>
      <template v-else>
        <el-button style="margin-left: 20px" type="primary" @click="save">{{ $t("保存") }}
        </el-button>
        <el-button style="margin-left: 20px" type="warning" @click="(ischeck = true), (isedit = true)">{{ $t("取消") }}
        </el-button>
      </template>
      <span style="display: block;margin-top: 5px;font-size: 17px;font-weight: 400;">{{ releaseNotes }}</span>
      <span style="margin-top: 5px;font-size: 17px;font-weight: 400;">
        {{ $t('下载链接：') }}</span>
      <el-input style="width: 400px" :disabled="ischeck" v-model="downloadUrl"></el-input>
    </el-card>
  </div>
</template>
<script>
import {
  editAppVersionApi,
  getAppVersionApi,
} from "@/api/appuser/appVersion.js";

export default {
  data() {
    return {
      ischeck: true,
      isedit: true,
      versionCode: "",
      releaseNotes: "",
      downloadUrl: "",
      loading: false,
    };
  },
  created() {
    this.getAppVersion();
  },
  methods: {
    edit() {
      this.isedit = false;
      this.ischeck = false;
    },
    async save() {
      this.isedit = true;
      this.ischeck = true;
      console.log(this.versionName);
      if (!this.versionCode) {
        return this.$message.error(`${this.$t("请填写app版本")}`);
      }
      const res = await editAppVersionApi({
        id: 1,
        versionName: this.versionCode,
        downloadUrl: this.downloadUrl
      });
      console.log(res);
      this.$message.success(`${this.$t("修改成功")}`);
    },
    async getAppVersion() {
      this.loading = true;
      const res = await getAppVersionApi();
      console.log(res.rows[0].versionName);
      this.versionCode = res.rows[0].versionName;
      this.releaseNotes = res.rows[0].releaseNotes;
      this.downloadUrl = res.rows[0].downloadUrl;
      console.log(this.versionCode);
      this.loading = false;
    },
  },
};
</script>
<style lang="" scoped></style>
